package com.eling.elcms.community.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.OrderCriteriaEnhancer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.system.service.impl.BuildingPrivilegeCriteriaEnhancer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.FieldBridge;
import org.hibernate.search.annotations.Indexed;

import javax.persistence.*;

/**
 * 楼宇
 * 
 * @author KEN
 *
 */
@Entity
@Table(name = "cm_building")
@Indexed
@CriteriaEnhancers(criteriaEnhancers = {
		@CriteriaEnhancer(impl = BuildingPrivilegeCriteriaEnhancer.class, parameter = "this"),
		@CriteriaEnhancer(impl = OrderCriteriaEnhancer.class, parameter = "orderCode") })
public class Building extends BaseModel {
	private static final long serialVersionUID = -2666445583431972847L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@In
	private Long pkBuilding;

	@Column(length = 30)
	@Field
	private String name;

	@Column
	private Integer orderCode;

	/** 楼层数 */
	@Column(nullable = false)
	private Integer floors;

	/** 用途 */
	@Enumerated(EnumType.STRING)
	@Field
	@FieldBridge(impl = EnumBridge.class)
	private UseType useType;

	/** 描述 */
	@Column(length = 1024)
	@Field
	private String description;

	/** 所属社区 */
	@ManyToOne(optional = false)
	@JoinColumn(name = "pkCommunity", nullable = false, updatable = false)
	private Community community;

	@Version
	private Integer version;

	public Long getPkBuilding() {
		return pkBuilding;
	}

	public void setPkBuilding(Long pkBuilding) {
		this.pkBuilding = pkBuilding;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getFloors() {
		return floors;
	}

	public void setFloors(Integer floors) {
		this.floors = floors;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public UseType getUseType() {
		return useType;
	}

	public void setUseType(UseType useType) {
		this.useType = useType;
	}

	public Community getCommunity() {
		return community;
	}

	public void setCommunity(Community community) {
		this.community = community;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public Integer getOrderCode() {
		return orderCode;
	}

	public void setOrderCode(Integer orderCode) {
		this.orderCode = orderCode;
	}

	/**
	 * 房间用途
	 * 
	 * @author
	 *
	 */
	@JsonSerialize(using = EnumSerializer.class)
	public static enum UseType {
		Apartment("公寓"), Hotel("酒店"), Hospital("医院"), Office("办公"), Demo("演示");

		private String display;

		UseType(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}
}
